package org.bozo.im.service.protocols.xmpp.stanza.processor.session;

import java.io.IOException;

import org.bozo.im.service.Constants;
import org.bozo.im.service.protocols.xmpp.XMPPSession;
import org.bozo.im.service.protocols.xmpp.stanza.Stanza;
import org.bozo.im.service.protocols.xmpp.stanza.processor.StanzaProcessor;
import org.bozo.im.service.protocols.xmpp.stanza.processor.stream.FeaturesStanzaProcessor;
import org.bozo.im.service.protocols.xmpp.stanza.task.session.SessionTask;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Log;

public class SessionStanzaProcessor extends StanzaProcessor {

	private static SessionStanzaProcessor mInstance;
	
	private SessionStanzaProcessor() {}
	
	public static SessionStanzaProcessor getInstance() {
		if (mInstance == null)
			mInstance = new SessionStanzaProcessor();
		return mInstance;
	}
	
	@Override
	public Stanza getStanza() {
		return Stanza.SESSION_SESSION;
	}

	@Override
	public void processStanza(XmlPullParser pParser, XMPPSession pSession, StanzaProcessor pParentProcessor) throws XmlPullParserException, IOException {

		if (pParentProcessor == FeaturesStanzaProcessor.getInstance()) {
			// ---------------------------------------------------------------------------------------
			Log.d(Constants.ACTIVITY_TAG, "org.bozo.im.xmpp.stanza.processor.session.SessionStanzaProcessor.processStanza ---------- Ready to start Session negociation");
			// ---------------------------------------------------------------------------------------
		
			pSession.getTaskProcessor().pushTask(new SessionTask(pSession.getId()));
			
		} else {
			// ---------------------------------------------------------------------------------------
			Log.d(Constants.ACTIVITY_TAG, "org.bozo.im.xmpp.stanza.processor.session.SessionStanzaProcessor.processStanza ---------- I don't know what to do with this Stanza");
			// ---------------------------------------------------------------------------------------
		}
	}
}
